﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using YawetagDemo.Framework.Data;
using YawetagDemo.Framework.Server.Services;
using YawetagDemo.Framework.Services;
using YawetagLib.System.ServiceModel;

namespace YawetagDemo.Framework.Client.Services
{
    public class WCFCoreServiceProxy : ServiceProxy<IWCFCoreService>, ICoreService
    {
        public WCFCoreServiceProxy() 
        {
            ChannelFactory = new ChannelFactory<IWCFCoreService>(new NetTcpBinding(SecurityMode.None, true));
            Service = ChannelFactory.CreateChannel(new EndpointAddress("net.tcp://localhost:3000/CoreService"));
        }

        public IPerson GetPerson(int personID)
        {
            return Service.GetPerson(personID);
        }

        public IList<IPerson> GetPersons()
        {
            return Service.GetPersons().OfType<IPerson>().ToList();
        }

        public IPerson CreatePerson(string name, DateTime? dob)
        {
            return Service.CreatePerson(name, dob);
        }

        public IPerson UpdatePerson(int personID, string name, DateTime? dob)
        {
            return Service.UpdatePerson(personID, name, dob);
        }

        public void DeletePerson(int personID)
        {
            Service.DeletePerson(personID);
        }
    }
}
